﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Threading
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(textBox1.Text) && !String.IsNullOrEmpty(textBox2.Text))
            {
                Operar(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
            }
        }
        private OperationDelegate _operationDelaegate= new OperationDelegate(Operation.Suma);
        private IAsyncResult _mensajeroAsignado;
        private int Operar(int a,int b)
        {
            _mensajeroAsignado = _operationDelaegate.BeginInvoke(a, b, null, null);            
            
            return -1;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox3.Text = _operationDelaegate.EndInvoke(_mensajeroAsignado).ToString();
        }

  
    }
}
